﻿using System;
using MongoDB.Driver;
using MongoDB.Bson.Serialization.Attributes;
using System.Threading.Tasks;
using System.Data;
using System.Reflection;

namespace MongoDBDemo
{
    public class A
    {
        public A()
        {
            Console.WriteLine("我是A");
        }
    }

    public class B : A
    {
        public B()
        {
            Console.WriteLine("我是B");
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            B b = new B();
            

            return;
            //var database = "BookstoreDb";
            //var collection = "Books";

            //var db = new MongoClient("mongodb://localhost:27017/").GetDatabase(database);
            //var coll = db.GetCollection<TestMongo>(collection);

            //var entity = new TestMongo
            //{
            //    Name = "SkyChen",
            //    Price = 100,
            //    Category = "",
            //    Author = "zxl"
            //};

            //var task = MongoHelper<TestMongo>.Insert(coll, entity);

            MemberInfo info = typeof(TestMongo);

            MessageAttribute hobbyAttr = (MessageAttribute)Attribute.GetCustomAttribute(info, typeof(MessageAttribute));

            Console.WriteLine("类名：{0}", info.Name);
            Console.WriteLine("创建时间：{0}", hobbyAttr.createTime);
            Console.WriteLine("创建人：{0}", hobbyAttr.createName);
            Console.WriteLine("备注消息：{0}", hobbyAttr.mess);
        }
    }

    [Message("1231", "1231231", "hahaha")]
    public class TestMongo : MongoEntity
    {
        //[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        //public DateTime CreateDateTime { get; set; }

        public string Name { get; set; }
        public decimal Price { get; set; }
        public string Category { get; set; }
        public string Author { get; set; }
    }

    [AttributeUsage(AttributeTargets.All)]
    public class MessageAttribute : Attribute
    {
        public MessageAttribute()
        {

        }
        public string createName { get; set; }
        public string createTime { get; set; }
        public string mess { get; set; }

        public MessageAttribute(string createTime, string createName, string mess)
        {
            this.createName = createName;
            this.createTime = createTime;
            this.mess = mess;
        }
    }
}
